package com.github.limit.response;

import org.springframework.lang.Nullable;

/**
 * @author: wangdejun
 * @create: 2019-10-14 18:53
 **/
public class Response<T> {

    private Integer code;
    private String message;
    private T data;

    private Response(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private Integer code;
        private String message;

        public Builder code(Integer code) {
            this.code = code;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public <T> Response<T> data(@Nullable T data) {
            return new Response<>(this.code, this.message, data);
        }

        public <T> Response<T> build() {
            return data(null);
        }

    }
}
